﻿/*
 *Copyright(C) 2024 by CometGamming All rights reserved.
 *Unity版本：2022.3.43f1c1 
 *作者:程一峰  
 *创建日期: 2024-10-22 
 *模块说明：简易状态机
 *版本: 0.1.0
*/

using Sirenix.OdinInspector;
using UnityEngine;

namespace Warfare.FSM
{
    /// <summary>
    /// 简易状态机运行示例
    /// </summary>
    public class FSMRunner : MonoBehaviour
    {

        [LabelText("状态机配置资源")]
        public FSMAsset Asset;

        [LabelText("状态机运行目标")]
        [ShowInInspector]
        public GameObject ActorObj;

        [LabelText("状态机上下文")]
        [ShowInInspector]
        public GameObject ContextObj;

        private void Start()
        {
            var Actor = ActorObj.GetComponent<I_FSMActor>();
            var Context = ActorObj.GetComponent<I_FSMContext>();
            machine = FSMMachine.Create(Asset, Context, Actor);
            machine.Run();
        }

        [Title("当前运行状态")]
        [HideReferenceObjectPicker, HideLabel]
        [ShowInInspector, HideInEditorMode]
        private FSMMachine machine;

        private void Update()
        {
            float deltaTime = Time.realtimeSinceStartup;
            machine?.Update(deltaTime);
        }

    }
}
